package org.ljy.testdemo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

//@Component
@Aspect
@Slf4j
public class TimeRecordAspect {

    @Pointcut("execution(* org.ljy.testdemo.controller.*.*(..))")
    public void pt(){};

    @Around("pt()")
    public Object recordTime(ProceedingJoinPoint point) throws Throwable {
        //1.记录开始时间
        log.info("--------------------");
        long start = System.currentTimeMillis();
        //2.执行目标方法
        Object proceed = point.proceed();
        //3.
        log.info(point.getSignature()+"耗时："+(System.currentTimeMillis()-start)+"ms");
        return proceed;
    }

    @Before("pt()")
    public void doBefore() {
        log.info("执行doBefore方法");
    }



}
